package com.mars.kafkademo.interceptor;

import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Map;

/**
 * author by: mars
 * Date: 2020/5/4 11:41
 * Description: kafka  拦截器
 */
public class TimeInterceptor implements ProducerInterceptor<String,String> {

    @Override
    public ProducerRecord<String, String> onSend(ProducerRecord<String, String> record) {
        // record 是生产者send之前的组装,对原始数据进行加工
        return new ProducerRecord<String,String>(
                record.topic(),
                record.partition(),
                record.key(),
                System.currentTimeMillis() + "-" +record.value());
    }

    @Override
    public void onAcknowledgement(RecordMetadata metadata, Exception exception) {

    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> configs) {

    }
}
